package com.fangsiqi.mashibing;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

public class CompanyTest {
	private static int count;

	public static synchronized void increment() throws InterruptedException{
		TimeUnit.MILLISECONDS.sleep(100);
		count++;
	}

	public static void main(String[] args) {
		// Duration duration=Duration.
		Thread t1=new Thread(()->{
			for (int i = 0; i < 100; i++) {
				try {
					increment();
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
			}
		});

		Thread t2=new Thread(()->{
			for (int i = 0; i < 100; i++) {
				try {
					increment();
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
			}
		});

		t1.start();t2.start();
		try {
			t1.join();
			t2.join();
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
		// t2.join();
		System.out.println(count);
	}
}
